#ifndef __SHOOT_H
#define __SHOOT_H

#include <hardware_config.h>
#include <main.h>
#include <motor_config.h>
#include <pid.h>

/**
 * @brief 摩擦轮状态
 *
 */
typedef enum {
    FRICTION_STATE_STOP = 0,  // 停止
    FRICTION_STATE_SLOW_IN,   // 加速
    FRICTION_STATE_SLOW_OUT,  // 减速
    FRICTION_STATE_READY,     // 准备就绪
} friction_state_t;
/**
 * @brief 拨弹轮状态
 *
 */
typedef enum {
    PLUNK_STATE_STOP = 0,  // 停止转动
    PLUNK_STATE_WORK,      // 转动
} plunk_state_t;
typedef struct shoot_behavior {
    friction_state_t  friction_state_;
    volatile uint16_t friction_speed_;	//一级摩擦轮
		volatile uint16_t friction_speed_2;	//二级摩擦轮
    plunk_state_t     plunk_state_;
    volatile bool pillwarehouse_state;
} shoot_behavior_t;

class Shoot {
   public:
    Shoot(void);

    void init(void);
    void set_friction(friction_state_t friction_state, uint16_t friction_speed,uint16_t friction_speed_2);
    void set_plunk(plunk_state_t plunk_state);
    void update(uint8_t id, uint8_t data[8]);
    void contrl_pillwarehouse(bool state);
    void set_pillwarehouse(bool state);
    bool get_pillwarehouse(void);

		void    set_current(int16_t shoot_id_1, int16_t shoot_id_2,int16_t shoot_id_3,int16_t shoot_id_4);
    void    friction_pid_set(void);
    int     get_friction_state(void);
    void    plunk_pid_set(void);
    uint8_t friction_action(void);
    void    plunk_action(uint8_t plunk_lock);
		void 		tuidam(void);
    void    handle(void);
    void    debug(void);
	 
	  /*步改英新增部分*/
		void    set_speed(uint16_t shoot42_speed_limit,uint16_t shoot42_speed_limit_2);
		void shoot(void);
	

		fp32    plunk_real_angle;		
		m3508_t          plunk_;           // 拨弹轮电机
		fp32    plunk_expect_angle;
		int16_t plunk_last_angle;
    fp32    plunk_angle;

   private:
    m3508_t          friction_[4];     // 摩擦轮电机
    friction_state_t friction_state_;  // 摩擦轮状态

    plunk_state_t    plunk_state_;     // 拨弹轮状态
    shoot_behavior_t behavior_;        // 期望缓存

    uint8_t is_stuck;  // 是否卡弹

    ramp_function_source_t ramp_friction_[2];          // 摩擦轮斜坡结构体
    pid_type_t             friction_pid_speed_[4];  // 摩擦轮 PID
    pid_type_t             plunk_pid_speed_;        // 拨弹轮 PID
	 
	  /*步改英新增部分*/
		uint16_t FRICTION_42_SPEED;
		uint16_t FRICTION_42_SPEED_2;
	  uint16_t 					keep_time;
	  int time;
	  pid_type_t             plunk_pid_angle_;        // 拨弹轮 PID


	 


		uint8_t stuck_flag;	
	 
    static void timeout(void *parameter);
    rt_timer_t  timer_;  // 发射机构定时器
};

extern Shoot shoot;

#endif
